package com.ruoyi.inventory.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.inventory.mapper.MaterialInventoryMapper;
import com.ruoyi.inventory.domain.MaterialInventory;
import com.ruoyi.inventory.service.IMaterialInventoryService;

/**
 * 物资库存Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Service
public class MaterialInventoryServiceImpl implements IMaterialInventoryService 
{
    @Autowired
    private MaterialInventoryMapper materialInventoryMapper;

    /**
     * 查询物资库存
     * 
     * @param inventoryId 物资库存主键
     * @return 物资库存
     */
    @Override
    public MaterialInventory selectMaterialInventoryByInventoryId(Long inventoryId)
    {
        return materialInventoryMapper.selectMaterialInventoryByInventoryId(inventoryId);
    }

    /**
     * 查询物资库存列表
     * 
     * @param materialInventory 物资库存
     * @return 物资库存
     */
    @Override
    public List<MaterialInventory> selectMaterialInventoryList(MaterialInventory materialInventory)
    {
        return materialInventoryMapper.selectMaterialInventoryList(materialInventory);
    }

    /**
     * 新增物资库存
     * 
     * @param materialInventory 物资库存
     * @return 结果
     */
    @Override
    public int insertMaterialInventory(MaterialInventory materialInventory)
    {
        // 先查询是否已存在
        MaterialInventory existing = materialInventoryMapper.selectMaterialInventoryByInventoryId(materialInventory.getMaterialId());
        if (existing != null) {
            throw new ServiceException("该物资已存在库存记录，不能重复添加");
        }
        return materialInventoryMapper.insertMaterialInventory(materialInventory);
    }

    /**
     * 修改物资库存
     * 
     * @param materialInventory 物资库存
     * @return 结果
     */
    @Override
    public int updateMaterialInventory(MaterialInventory materialInventory)
    {
        return materialInventoryMapper.updateMaterialInventory(materialInventory);
    }

    /**
     * 批量删除物资库存
     * 
     * @param inventoryIds 需要删除的物资库存主键
     * @return 结果
     */
    @Override
    public int deleteMaterialInventoryByInventoryIds(Long[] inventoryIds)
    {
        return materialInventoryMapper.deleteMaterialInventoryByInventoryIds(inventoryIds);
    }

    /**
     * 删除物资库存信息
     * 
     * @param inventoryId 物资库存主键
     * @return 结果
     */
    @Override
    public int deleteMaterialInventoryByInventoryId(Long inventoryId)
    {
        return materialInventoryMapper.deleteMaterialInventoryByInventoryId(inventoryId);
    }
}
